<?php
/**
 * 班级控制器 
 * @date 2014/01/11  
 * @author 马燕龙
 */
class GradeAction extends CommonAction{

	public function index2(){

		$list = D('Grade')->relation(true)->order('id desc')->select();
		dump($list);


	}
	//班级列表
	public function index(){
			
		$Grade = D('Grade');		
		$map = array();
		$count = $Grade->where($map)->count();

		import('ORG.Util.Page');
		$Page = new Page($count);
		$show = $Page->show();

		$list = $Grade->where($map)->order('id desc')->limit($Page->firstRow .','. $Page->listRows)->select();
		$list = $Grade->changeStatus($list);
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();

	}

	//添加班级
	public function add(){
		$Grade = D('Grade');
		//处理添加
		if(!empty($_POST)){
			
			if($Grade->create()){
				$result = $Grade->add();
				if($result){
					$this->success('添加班级成功！');
				}else{
					$this->error('添加班级失败！');
				}
			}else{
				$this->error($Grade->getError());
			}
			exit;
		}

		$this->assign('status',$Grade->status);		
		$this->display();
	}

	//修改班级
	public function edit(){
		
		$Grade = D('Grade');
		
		//处理修改
		if(!empty($_POST)){
			if($Grade->create()){
				$result = $Grade->save();
				if($result){
					$this->success('修改成功！',U('index'));
				}else{
					$this->error('修改失败');
				}
			}else{
				$this->error($Grade->getError());
			}
			exit;
		}

		$id = I('id');
		$data=$Grade->find($id);

		$this->assign('item',$data);
		$this->assign('status',$Grade->status);	
		$this->display();
	}
}